package com.inei.evaluacionemype.controller.activity;

import com.inei.evaluacionemype.R;
import com.inei.evaluacionemype.R.drawable;
import com.inei.evaluacionemype.R.style;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class CapituloI_Activity extends Activity {

	// componentes
	private EditText et01, et02, et03, et04, et05, et06, et08, et09, et10,
			et11, et12, et13, et14, et15, et16, et17, et18, et20, et231, et232,
			et233, et234, et235;
	private Spinner sp07, sp191, sp192, sp193, sp21, sp22;

	// variables

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_capitulo_i);

		IniciarComponentes();

		AgregarEventos();

		CargarDatos();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.capitulo_i, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.mnGuardar:
			String resultado = Validar();
			if (resultado.equals("")) {
				GuardarDatos();
				break;
			} else {
				Toast.makeText(this, resultado, Toast.LENGTH_SHORT).show();
				break;
			}

		case R.id.mnSalir:
			finish();
			break;

		default:
			break;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onBackPressed() {
		super.onBackPressed();
	}

	private void IniciarComponentes() {
		et01 = (EditText) findViewById(R.id.et01);
		et02 = (EditText) findViewById(R.id.et02);
		et03 = (EditText) findViewById(R.id.et03);
		et04 = (EditText) findViewById(R.id.et04);
		et05 = (EditText) findViewById(R.id.et05);
		et06 = (EditText) findViewById(R.id.et06);
		et08 = (EditText) findViewById(R.id.et08);
		et09 = (EditText) findViewById(R.id.et09);
		et10 = (EditText) findViewById(R.id.et10);
		et11 = (EditText) findViewById(R.id.et11);
		et12 = (EditText) findViewById(R.id.et12);
		et13 = (EditText) findViewById(R.id.et13);
		et14 = (EditText) findViewById(R.id.et14);
		et15 = (EditText) findViewById(R.id.et15);
		et16 = (EditText) findViewById(R.id.et16);
		et17 = (EditText) findViewById(R.id.et17);
		et18 = (EditText) findViewById(R.id.et18);
		et20 = (EditText) findViewById(R.id.et20);
		et231 = (EditText) findViewById(R.id.et231);
		et232 = (EditText) findViewById(R.id.et232);
		et233 = (EditText) findViewById(R.id.et233);
		et234 = (EditText) findViewById(R.id.et234);
		et235 = (EditText) findViewById(R.id.et235);

		sp07 = (Spinner) findViewById(R.id.sp07);
		sp191 = (Spinner) findViewById(R.id.sp191);
		sp192 = (Spinner) findViewById(R.id.sp192);
		sp193 = (Spinner) findViewById(R.id.sp193);
		sp21 = (Spinner) findViewById(R.id.sp21);
		sp22 = (Spinner) findViewById(R.id.sp22);
	}

	private void AgregarEventos() {

	}

	private void CargarDatos() {

	}

	private void GuardarDatos() {
		Intent ir_cap2 = new Intent(this, CapituloII_Activity.class);
		startActivity(ir_cap2);
		finish();
	}

	private String Validar() {
		if (et01.getText().toString().trim().length() == 0) {
			et01.requestFocus();
			et01.setBackgroundColor(Color.rgb(255, 96, 96));
			return "1. Campo vac\u00edo";
		} else {
			et01.setBackgroundResource(R.drawable.celda);
		}
		if (et02.getText().toString().trim().length() == 0) {
			et02.requestFocus();
			return "2. Campo vac\u00edo.";
		}
		if (et04.getText().toString().trim().length() == 0) {
			et04.requestFocus();
			return "4. Campo vac\u00edo";
		}
		if (sp07.getSelectedItemPosition() == 0) {
			return "7. Debe seleccionar una opci\u00f3n.";
		}
		if (et08.getText().toString().trim().length() == 0) {
			et08.requestFocus();
			return "8. Campo vac\u00edo";
		}
		if (et11.getText().toString().trim().length() == 0) {
			et11.requestFocus();
			return "11. Campo vac\u00edo";
		}
		if (et15.getText().toString().trim().length() == 0) {
			et15.requestFocus();
			return "15. Campo vac\u00edo";
		}
		if (et16.getText().toString().trim().length() == 0) {
			et16.requestFocus();
			return "16. Campo vac\u00edo";
		}
		if (sp191.getSelectedItemPosition() == 0) {
			sp191.requestFocus();
			return "19. Debe seleccionar Departamento";
		}
		if (sp192.getSelectedItemPosition() == 0) {
			sp192.requestFocus();
			return "19. Debe seleccionar Provincia";
		}
		if (sp193.getSelectedItemPosition() == 0) {
			sp193.requestFocus();
			return "19. Debe seleccionar Distrito";
		}
		if (et20.getText().toString().trim().length() == 0) {
			et20.requestFocus();
			return "20. Campo vac\u00edo";
		}
		if (sp21.getSelectedItemPosition() == 0) {
			sp21.requestFocus();
			return "21. Debe seleccionar una opci\u00f3n";
		}
		if (sp22.getSelectedItemPosition() == 0) {
			sp22.requestFocus();
			return "22. Debe seleccionar una opci\u00f3n";
		}

		return "";
	}
}
